package mspbots.timedoctor.client.core.controller;

import mspbots.timedoctor.client.core.api.constant.API;
import mspbots.timedoctor.client.oauth.V2AuthService;
import mspbots.timedoctor.client.tigger.AsyncScheduleEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/timedoctor")
public class TimeDoctorController {

    @Autowired
    private V2AuthService v2AuthService;
    @Autowired
    private AsyncScheduleEvent asyncScheduleEvent;


    @GetMapping("apilist")
    public List<String> apiList() {
        List<String> list = new ArrayList<>();

        list.add(API.V2_COMPANIES);
        list.add(API.V2_FOLDERS);
        list.add(API.V2_PROJECTS);
        list.add(API.V2_TASKS);
        list.add(API.V2_USERS_ALL);
        list.add(API.V2_WORKLOG);

        return list;
    }

    /**
     * {
     * "email":"",
     * "password":"",
     * "tenantId":1001,
     * "subjectCode":"TD"
     * }
     *
     * @param params
     * @return
     */
    @PostMapping("test")
    public Mono<Boolean> test(@RequestBody Map<String, Object> params) {
        return v2AuthService.test(params);
    }

    /**
     * {
     * <p>
     * "tenantId":1001
     * <p>
     * }
     *
     * @param params
     */
    @PostMapping("synchronise")
    public void synchronise(@RequestBody Map<String, Object> params) {
        asyncScheduleEvent.manualSynchronise(params);
    }

    /**
     * {
     * <p>
     * "tenantId":1001,
     * "onoff":"ON"
     * <p>
     * }
     *
     * @param params
     */
    @PostMapping("onoff")
    public void onoff(@RequestBody Map<String, Object> params) {
        asyncScheduleEvent.manualOnoffSynchronise(params);
    }
}
